package com.snakerflow.framework.utils;

import java.io.IOException;
import java.util.Properties;

public class SeqenceUtils {
	private static String code = null;
	private static Character end = 'Z';
	private static Properties p = new Properties();
	private static String employeePosistionId = null;
	private static String HRposistionCode = null;
	private static String bossposistionCode = null;
	static{
		try {
			p.load(SeqenceUtils.class.getClassLoader().getResourceAsStream("snaker.properties"));
			code = p.getProperty("posistionCode");
			employeePosistionId = p.getProperty("employeePosistionId");
			HRposistionCode = p.getProperty("HRposistionCode");
			bossposistionCode = p.getProperty("bossposistionCode");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 获取普通员工岗位ID
	 * @return
	 */
	public static String getEmployeePosistionId(){
		return employeePosistionId;
	}
	/**
	 * 获取HR岗位代码
	 * @return
	 */
	public static String getHRposistionCode(){
		return HRposistionCode;
	}
	
	/**
	 * 获取Boss岗位代码
	 * @return
	 */
	public static String getBossposistionCode(){
		return bossposistionCode;
	}
	
	public static String getSeq(){
		if(code == null || "".equals(code)){
			code = "A";
			return code;
		}
		int len = code.length();
		if(len == 1){
			StringBuffer buffer = new StringBuffer();
			Character ch = code.charAt(0);
			if(end.equals(ch)){
				buffer.append("AA");
			}else{
				buffer.append(++ch);
			}
			code = buffer.toString();
		}else{
			int count = 1;
			StringBuffer buffer = new StringBuffer(code);
			Character ch = code.charAt(len-count);
			while(true){
				if(!end.equals(ch) || count > len){
					buffer.replace(len-count, len-count+1, (++ch).toString());
					break;
				}
				buffer.replace(len-count, len-count+1, "A");
				count++;
				ch = code.charAt(len-count);
			}
			code = buffer.toString();
		}
		return code;
	}
	
}
